package com.thinkinjava;


import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.regex.Pattern;

/**
 * @Description 类方法提取器
 * @Author
 * @Date 2019/9/30 20:38
 **/
public class ShowMethods {

    private static Pattern pattern = Pattern.compile("\\w+\\.");

    public static void main(String[] args) {
        try {
            Class<?> c = Class.forName("com.thinkinjava.ShowMethods");
            Object o = c.newInstance();
            Constructor<?> constructor = c.getConstructor(null);
            Object o1 = constructor.newInstance();
            Method[] methods = c.getMethods();
            Constructor<?>[] constructors = c.getConstructors();
            for (int i = 0; i < methods.length; i++) {
                System.out.println(pattern.matcher(methods[i].toString()).replaceAll(""));
            }
            for (int i = 0; i < constructors.length; i++) {
                ShowMethods showMethods = (ShowMethods) constructors[i].newInstance();
                showMethods.toString();
                System.out.println(pattern.matcher(constructors[i].toString()).replaceAll(""));
            }
        } catch (ClassNotFoundException e) {
            System.out.println(e.getCause());
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
    }
}
